package com.xquant.marketdata.marketdata.controller;

import com.xquant.marketdata.marketdata.domain.*;
import com.xquant.marketdata.marketdata.service.TcmdtService;
import com.xquant.common.security.utils.ExcelUtil;
import com.xquant.common.core.web.controller.BaseController;
import com.xquant.common.core.web.page.TableDataInfo;
import com.xquant.common.log.annotation.Log;
import com.xquant.common.log.enums.BusinessType;
import com.xquant.marketdata.utils.CommResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 下拉框查询
 *
 * @author ershuai.zhao
 */
@RestController
@RequestMapping("tcmdtController")
public class TcmdtController extends BaseController {

    @Autowired
    private TcmdtService tcmdtService;

    /**
     * 查询商品信息
     */
    //@PreAuthorize("@ss.hasPermi('marketdata:commodity:commodity:list')")
    @RequestMapping(value = "/queryTcmdtInfoByPage.action")
    public TableDataInfo queryTcmdtInfoByPage(@RequestParam Map<String, Object> param) {
        List<CmdtInfoDTO> list = tcmdtService.queryTcmdtInfoByPage(param);
        for (CmdtInfoDTO tfndDTO : list) {
            tfndDTO.setInstrument(tfndDTO.getiCode()+ " " +tfndDTO.getaType()+" " +tfndDTO.getmType());
        }
        return getDataTable(list);
    }

    /**
     * 修改商品行情
     */
    @PreAuthorize("@ss.hasPermi('marketdata:commodity:commodityPrice:update')")
    @RequestMapping(value = "/updateTcmdtPrice.action")
    public CommResponse updateTcmdtPrice(@RequestBody CmdtPriceDTO cmdtFrom) {
        tcmdtService.updateTcmdtPrice(cmdtFrom);
        return CommResponse.success();
    }

    /**
     * 查询商品行情
     */
    @PreAuthorize("@ss.hasPermi('marketdata:commodity:commodityPrice:list')")
    @RequestMapping(value = "/queryTcmdtPriceByPage.action")
    public TableDataInfo queryTcmdtPriceByPage(@RequestParam Map<String, Object> param) {
        startPage();
        return getDataTable(tcmdtService.queryTcmdtPriceByPage(param));
    }

    /**
     * 查询商品期货信息
     */
    //@PreAuthorize("@ss.hasPermi('marketdata:commodity:futures:list')")
    @RequestMapping(value = "/queryTcmdtFutureByPage.action")
    public TableDataInfo queryTcmdtFutureByPage(@RequestParam Map<String, Object> param) {
        List<TcmdtfutureDTO> list = tcmdtService.selectTcmdtfutureList(param);
        for (TcmdtfutureDTO tfndDTO : list) {
            tfndDTO.setInstrument(tfndDTO.getiCode()+ " " +tfndDTO.getaType()+" " +tfndDTO.getmType());
        }
        return getDataTable(list);
    }

    /**
     * 查询商品期货行情信息
     */
    @RequestMapping(value = "/queryTcmdtFuturePriceByPage.action")
    @PreAuthorize("@ss.hasPermi('marketdata:commodity:futuresPrice:list')")
    public TableDataInfo queryTcmdtFuturePriceByPage(@RequestParam Map<String, Object> param) {
        startPage();
        return getDataTable(tcmdtService.selectTcmdtfuturePriceList(param));
    }

    /**
     * 修改商品期货行情
     */
    @RequestMapping(value = "/updateTcmdtFuturePrice.action")
    @PreAuthorize("@ss.hasPermi('marketdata:commodity:futuresPrice:update')")
    public CommResponse updateTcmdtFuturePrice(@RequestBody TcmdtfuturePriceDTO cmdtFutureFrom) {
        tcmdtService.updateTcmdtFuturePrice(cmdtFutureFrom);
        return CommResponse.success();
    }

    /**
     * 查询商品延期行情信息
     */
    @RequestMapping(value = "/queryTcmdtelPriceByPage.action")
    @PreAuthorize("@ss.hasPermi('marketdata:commodity:delayPrice:list')")
    public TableDataInfo queryTcmdtelPriceByPage(@RequestParam Map<String, Object> param) {
        startPage();
        return getDataTable(tcmdtService.selectTcmdtdelPriceList(param));
    }

    /**
     * 查询商品延期信息
     */
    @RequestMapping(value = "/queryTcmdtdelByPage.action")
    @PreAuthorize("@ss.hasPermi('marketdata:commodity:delay:list')")
    public TableDataInfo queryTcmdtdelByPage(@RequestParam Map<String, Object> param) {
        startPage();
        return getDataTable(tcmdtService.selectTcmdtdelList(param));
    }

    /**
     * 修改商品延期行情
     */
    @RequestMapping(value = "/updateTcmdtDelPrice.action")
    public CommResponse updateTcmdtDelPrice(@RequestBody TcmdtdelPriceDTO delayFrom) {
        tcmdtService.updateTcmdtDelPrice(delayFrom);
        return CommResponse.success();
    }

    @Log(title = "商品信息", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('marketdata:commodity:commodity:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam Map<String, Object> param) {
        startPage();
        List<CmdtInfoDTO> list = tcmdtService.queryTcmdtInfoByPage(param);
        ExcelUtil<CmdtInfoDTO> util = new ExcelUtil<CmdtInfoDTO>(CmdtInfoDTO.class);
        util.exportExcel(response, list, "商品信息");
    }


    @Log(title = "商品行情", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('marketdata:commodity:commodityPrice:exportPrice')")
    @PostMapping("/exportPrice")
    public void exportPrice(HttpServletResponse response, @RequestParam Map<String, Object> param) {
        startPage();
        List<CmdtPriceDTO> list = tcmdtService.queryTcmdtPriceByPage(param);
        ExcelUtil<CmdtPriceDTO> util = new ExcelUtil<CmdtPriceDTO>(CmdtPriceDTO.class);
        util.exportExcel(response, list, "商品行情");
    }

    @Log(title = "商品期货行情", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('marketdata:commodity:futuresPrice:exportPrice')")
    @PostMapping("/exportFuturePrice")
    public void exportFuturePrice(HttpServletResponse response, @RequestParam Map<String, Object> param) {
        startPage();
        List<TcmdtfuturePriceDTO> list = tcmdtService.selectTcmdtfuturePriceList(param);
        ExcelUtil<TcmdtfuturePriceDTO> util = new ExcelUtil<TcmdtfuturePriceDTO>(TcmdtfuturePriceDTO.class);
        util.exportExcel(response, list, "商品期货行情");
    }

    @Log(title = "商品期货信息", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('marketdata:commodity:futureInfo:exportPrice')")
    @PostMapping("/exportFutureInfo")
    public void exportFutureInfo(HttpServletResponse response, @RequestParam Map<String, Object> param) {
        startPage();
        List<TcmdtfutureDTO> list = tcmdtService.selectTcmdtfutureList(param);
        ExcelUtil<TcmdtfutureDTO> util = new ExcelUtil<TcmdtfutureDTO>(TcmdtfutureDTO.class);
        util.exportExcel(response, list, "商品期货信息");
    }

    @Log(title = "商品延期行情", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('marketdata:commodity:delPrice:exportPrice')")
    @PostMapping("/exportdelPrice")
    public void exportdelPrice(HttpServletResponse response, @RequestParam Map<String, Object> param) {
        startPage();
        List<TcmdtdelPriceDTO> list = tcmdtService.selectTcmdtdelPriceList(param);
        ExcelUtil<TcmdtdelPriceDTO> util = new ExcelUtil<TcmdtdelPriceDTO>(TcmdtdelPriceDTO.class);
        util.exportExcel(response, list, "商品延期行情");
    }

    @Log(title = "商品延期信息", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('marketdata:commodity:delInfo:exportPrice')")
    @PostMapping("/exportdelInfo")
    public void exportdelInfo(HttpServletResponse response, @RequestParam Map<String, Object> param) {
        startPage();
        List<TcmdtdelDTO> list = tcmdtService.selectTcmdtdelList(param);
        ExcelUtil<TcmdtdelDTO> util = new ExcelUtil<TcmdtdelDTO>(TcmdtdelDTO.class);
        util.exportExcel(response, list, "商品延期信息");
    }

}
